cc.Class({
    extends: cc.Component,

    properties: {

    },


    onLoad() {

    },

    start() {
        let name = this.node.name;
        this.type = name.split('_')[1];
    },
    /**
     * 初始化
     */
    initInfor() {
        let name = this.node.parent.name;
        this.type = name.split('_')[1];
        let information = this.node.getChildByName("information");
        //左上角金币数量
        let coin = this.node.getChildByName("guileftup").getChildByName("New Label");
        this.coin = coin.getComponent(cc.Label);
        this.coin.string = cc.vv.CoinCount + " / " + cc.vv.CoinTotal;
        //右上角的死亡次数
        let death = this.node.getChildByName("guirightdown").getChildByName("New Label");
        this.death = death.getComponent(cc.Label);
        this.death.string = "X " + cc.vv.DeathNum;

        //过关后的弹框
        this.information = this.node.getChildByName("information");
        let coinTotal = this.information.getChildByName("coin");
        this.coinTotalTxt = coinTotal.getComponent(cc.Label);
        this.coinTotalTxt.string = cc.vv.CoinCount + " / " + cc.vv.CoinTotal;
        cc.vv["stageCoin" + this.type] = cc.vv.CoinCount;
        //弹框死亡次数
        let deathTxt = information.getChildByName("death");
        this.deathTxt = deathTxt.getComponent(cc.Label);
        this.deathTxt.string = "X " + cc.vv.DeathNum;
        cc.vv["stageDeath" + this.type] = cc.vv.DeathNum;
        if (cc.vv["stageCoin" + this.type] > cc.sys.localStorage.getItem('stageCoin' + this.type)) {
            //将数据保存至本地
            cc.sys.localStorage.setItem('stageCoin' + this.type, cc.vv["stageCoin" + this.type]);
            cc.sys.localStorage.setItem('stageDeath' + this.type, cc.vv["stageDeath" + this.type]);
        }
    },




    /**
     * 返回菜单
     */
    backMenu() {
        cc.director.loadScene("selectLevel");
    },

    /**
    * 重玩本关
    */
    reStart() {
        let name = this.node.getChildByName("guirightup").children[0].getComponent(cc.Sprite).spriteFrame.name;
        let type = name.split('_')[1];
        cc.director.loadScene("stage" + type);
    },

    /**
    * 下一关
    */
    nextLevel() {
        let name = this.node.getChildByName("guirightup").children[0].getComponent(cc.Sprite).spriteFrame.name;
        let type = name.split('_')[1];
        cc.director.loadScene("stage" + (parseInt(type) + 1));
    },
    update(dt) {
        this.initInfor();
    },
});
